<%-- 
    Document   : gioHangSubpage
    Created on : May 22, 2011, 1:49:23 PM
    Author     : Hong Lam
--%>

<%@page import="java.util.List"%>
<%@page import="Pojos.SanPham"%>
<%@page import="Pojos.GioHang"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">



<%

            ArrayList<GioHang> gioHang = (ArrayList<GioHang>) session.getAttribute("gioHang");
            if (gioHang == null) {
                gioHang = new ArrayList<GioHang>();
            }else{
                gioHang = (ArrayList<GioHang>) session.getAttribute("gioHang");
            }
            // <editor-fold defaultstate="collapsed" desc="Cập nhật số lượng">
                    String[] soLuong = request.getParameterValues("sanpham");
                    if (soLuong != null) {
                        for (int i = 0; i < soLuong.length; i++) {
                            gioHang.get(i).setSoLuong(Integer.parseInt(soLuong[i]));
                        }
                    }
           // </editor-fold>
           // <editor-fold defaultstate="collapsed" desc="Xóa sách">
                String[] maSanPhamCanXoa = request.getParameterValues("chkXoa");
                if (maSanPhamCanXoa != null) {
                    for (String maSp : maSanPhamCanXoa) {
                        for (GioHang gh : gioHang) {
                            if (gh.getSp().getMaSanPham().compareTo(maSp) == 0) {
                                gioHang.remove(gh);
                                break;
                            }
                        }
                    }
                }
           // </editor-fold>
            // <editor-fold defaultstate="collapsed" desc="Xóa hết">
                String action = request.getParameter("btnXoaHet.x");
                if (action != null && action.compareTo("") != 0) {
                    gioHang.clear();
                }
            // </editor-fold>
    %>
<form action="giohang.jsp" method="get" name="submitForm">
    <input type="hidden" id="action" name="action" value=""/>
    <link rel="stylesheet" type="text/css" href="/WebsiteBanHang/images/giohang/source/default.css">
    <link rel="stylesheet" type="text/css" href="/WebsiteBanHang/images/giohang/source/order.css">

    <table id="out" border="0" cellpadding="0" cellspacing="0" width="80%">
        <!-- bắt đầu giỏ hàng -->

        <tbody>

            <tr>

                <td align="left" valign="top"><table id="middle" border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tbody><tr>
                                <td align="center" valign="top">




                                    <table id="main" border="0" cellpadding="0" cellspacing="0" width="80%">

                                        <tbody><tr>
                                                <td align="left" valign="top">
                                                    <div style="padding:10px 0 10px 0"> <img src="/WebsiteBanHang/images/giohang/source/icon_cart.gif" align="absmiddle"><span class="text_title">Giỏ hàng </span> &nbsp;</div>
                                                    <div style="padding:20px 0 20px 0; color:#d17601; font-weight:bold;"> Tất cả những sản phẩm bạn đã chọn </div>
                                                    <table id="cart" border="0" cellpadding="0" cellspacing="0" width="112%">
                                                        <tbody><tr>
                                                                <td class="order_cart_title order_cart_left">Tên sản phẩm </td>
                                                                <td class="order_cart_title order_cart_right" nowrap="nowrap">Đơn giá (VNĐ)</td>
                                                                <td class="order_cart_title order_cart_center" nowrap="nowrap">Số lượng </td>
                                                                <td class="order_cart_title order_cart_center" nowrap="nowrap">Xóa</td>
                                                                <td class="order_cart_title order_cart_right" nowrap="nowrap">Thành tiền (VNĐ)</td>
                                                            </tr>
                                                            <%
                                                                        double thanhTien = 0;
                                                                        for(GioHang gh : gioHang){
                                                                            SanPham sp = gh.getSp();
                                                                            double tien = (sp.getGiaBan() * gh.getSoLuong());
                                                                            thanhTien += tien;
                                                                             request.setAttribute("Payment_Amount", thanhTien);

                                                            %>
                                                            <tr>
                                                                <td class="order_cart_line order_cart_left">
                                                                    <!--Bat dau thong in -->
                                                                    <a><%=sp.getTenSanPham()%></a> <br>

                                                                </td>
                                                                <td class="order_price order_cart_line order_cart_right" nowrap="nowrap"><%=sp.getGiaBan()%></td>
                                                                <td class="order_cart_line order_cart_center">
                                                                    <input name="sanpham" id="q43869" value="<%=gh.getSoLuong()%>" size="5" type="text">

                                                                </td>
                                                                <td class="order_cart_line order_cart_center" nowrap="nowrap"> <input type="checkbox" name="chkXoa" value="<%=sp.getMaSanPham()%>" /></td>
                                                                <td class="order_price order_cart_line order_cart_right" nowrap="nowrap"><%=Integer.toString((int)(gh.getThanhTien()))%></td>
                                                            </tr>
                                                             <%}%>
                                                            <tr>
                                                                <td class="order_cart_left" height="61"><a href="XemDanhSachSanPham.jsp"><image src="/WebsiteBanHang/images/giohang/source/cart_shopping.gif" border="0"></a></td>
                                                                <td></td>
                                                                   <td class="order_cart_center"><input name="bt_capnhat" id="capnhat"  src="/WebsiteBanHang/images/giohang/source/cart_update.gif" border="0" type="image"></td>
                                                                <td class="order_cart_center" > <input name="btnXoaHet" value="Xóa Hết"src="/WebsiteBanHang/images/giohang/source/cart_del.gif" border="0" type="image"></td>
                                                                <td class="order_cart_right order_cart_text_b" nowrap="nowrap">Tổng Số tiền<br>
                                                                    <span class="order_cart_total_price"> <%=Integer.toString((int)(thanhTien))%></span></td>
                                                            </tr>
                                                           
                                                        </tbody></table>
                                                    <table border="0" cellpadding="0" cellspacing="0" width="100%">

                                                    </table></td>
                                            </tr>
                                        </tbody></table>


                                </td>

                            </tr>

                            <tr>
                                <td align="right" height="40" valign="middle">
                                    <table width="50%" border="0">
                                      <tr>
                                        <td align="right" height="40" valign="middle">
                                    <a href="expresscheckout.jsp"><img src="/WebsiteBanHang/images/giohang/source/btn_xpressCheckout.gif" border="0"></a>

                                        </td>
                                        <td align="right" height="40" valign="middle">
                                    <a href="http://www.vinabook.com/order/?target=checkout"><img src="/WebsiteBanHang/images/giohang/source/cart_checkout.gif" border="0"></a>

                                </td>
                                      </tr>
                                    </table>



                                </td>
       
                                
                            </tr>
                        </tbody></table>


                    


                    <table style="background: url(&quot;/WebsiteBanHang/images/giohang/source/btInfo.jpg&quot;) repeat-x scroll 0% 0% transparent; height: 64px; border: 1px solid rgb(204, 204, 204); margin-top: 10px;" border="0" cellpadding="0" cellspacing="0" width="112%"><tbody><tr> <td width="3%">&nbsp;</td> <td width="19%"><img src="/WebsiteBanHang/images/giohang/source/giaohangSlogan.jpg" alt="Giao hang - Thu tien tan noi" height="33" width="196"></td> <td width="12%"><span style="font-family:Arial, Helvetica, sans-serif">Bạn có thể thanh toán <br>
                                        với<span style="color: #0f804d"> </span>website bằng:</span> </td><td align="center" width="6%"><img src="/WebsiteBanHang/images/giohang/source/visaCard.jpg" alt="Visa Credit Card" height="40" width="63"></td> <td align="center" width="6%"><img src="/WebsiteBanHang/images/giohang/source/mastercard.jpg" alt="MasterCard" height="40" width="62"></td> <td align="center" width="6%"><img src="/WebsiteBanHang/images/giohang/source/AmericaExpessCard.jpg" alt="American Express Card" height="40" width="63"></td> <td align="center" width="6%"><img src="/WebsiteBanHang/images/giohang/source/Paypal.jpg" alt="Paypal" height="40" width="63"></td> <td align="center" width="6%"><img src="/WebsiteBanHang/images/giohang/source/Payoo.jpg" alt="Payoo Vietnam" style="margin-right: 10px;" height="39" width="64"></td><td align="center" width="6%"><img src="/WebsiteBanHang/images/giohang/source/vnmartpayment.jpg" alt="Vnmart VnPay Vietnam" style="margin-right: 10px;" height="39" width="64"></td> <td style="border-right: 1px solid rgb(204, 204, 204);" align="center" width="7%"><img src="/WebsiteBanHang/images/giohang/source/vcashPayment.jpg" alt="Vinapay" style="margin-right: 10px;" height="39" width="64"></td>
                                <td width="12%"><span style="font-family:Arial, Helvetica, sans-serif; display: block; margin-left:10px;">Được chứng nhận giao dịch an toàn bởi:</span></td> <td align="left" width="9%"><a href="http://trustvn.org.vn/info.aspx?key=TWpjMWVrMWpORFp1U2c9PQ==" target="_blank"> <img src="/WebsiteBanHang/images/giohang/source/TrustVn.jpg" alt="TrustVn" border="0" height="39" width="64"></a></td> <td width="0%"></td></tr></tbody></table>

                </td>
            </tr>
            <tr>
                <td height="2"><img src="/WebsiteBanHang/images/giohang/source/space.gif" height="1" width="100%"></td>
            </tr>
        </tbody></table>


</form>
